import i18n from 'i18next'
import { LanguageAction, change_language } from './languageActions'

export interface LanguageState {
	language: 'zh' | 'en'
	languageList: {
		code: 'zh' | 'en'
		language: '中文' | '英文'
	}[]
}

const initState: LanguageState = {
	language: 'zh',
	languageList: [{
		code: 'zh',
		language: '中文'
	}, {
		code: 'en',
		language: '英文'
	}]
}


export default (state: LanguageState = initState, action: LanguageAction) => {
	switch (action.type) {
		case change_language:
			i18n.changeLanguage(action.payload)
			return {
				...state,
				language: action.payload
			}
		default:
			return state
	}
}

